#include <bits/stdc++.h>
using namespace std;

int n, m, fa[50004], a[50004], l[50004], r[50004];
vector<int> edges[50004];

namespace CRH380D {
	bool flg[50004];
	int ans = 0, dep[50004], ttot[50004], viss[50004];
	vector<int> deps[50004];
	void init(int i, int dp) {
		dep[i] = dp;
		deps[dp].push_back(i);
		for (auto j : edges[i]) {
			init(j, dp + 1);
		}
	}
	void main() {
		init(1, 1);
		int tot = 0;
		for (int dp = n; dp >= 1; --dp) {
			for (auto j : deps[dp]) {
				viss[++tot] = j;
			}
		}
		for (int i = 1; i <= m; ++i) {
			for (int j = l[i]; j <= r[i]; ++j) flg[a[j]] = 1;
			for (int i = 1; i <= n; ++i) ttot[i] = 0;
			ans = 0;
			for (int i = 1; i <= n; ++i) {
				int j = viss[i];
				int tot = ttot[j];
				if (tot >= 2) ans += !flg[j];
				ttot[fa[j]] += (tot || flg[j]);
			}
			cout << ans + (r[i] - l[i] + 1) << "\n";
			for (int j = l[i]; j <= r[i]; ++j) flg[a[j]] = 0;
		}
	}
}

namespace CRT5A {
	void main() {
		for (int i = 1; i <= m; ++i) {
			cout << r[i] - l[i] + 1 << "\n";
		}
	}
}

namespace CR400AF {
	bool flg[50004];
	int ans = 0, dfn[50004], dft, sz[50004];
	struct BIT {
		int t[50004];
		void update(int i, int x) {
			for (int j = i; j <= n; j += (j & (-j))) t[j] += x;
		}
		int _query(int i) {
			int sum = 0;
			while (i) {
				sum += t[i];
				i -= (i & (-i));
			}
			return sum;
		}
		int query(int l, int r) {
			return _query(r) - _query(l - 1);
		}
	} t;
	bool dfs(int i) {
		int tmp = t.query(dfn[i], dfn[i] + sz[i] - 1);
		if (tmp == 0) return 0;
		if (tmp == 1) return 1;
		int tot = 0;
		for (auto j : edges[i]) {
			tot += dfs(j);
		}
		if (tot >= 2) {
			ans += !flg[i];
		}
		return tot || flg[i];
	}
	void init(int i) {
		dfn[i] = ++dft;
		sz[i] = 1;
		for (auto j : edges[i]) {
			init(j);
			sz[i] += sz[j];
		}
	}
	void main() {
		init(1);
		for (int i = 1; i <= m; ++i) {
			for (int j = l[i]; j <= r[i]; ++j) {
				flg[a[j]] = 1;
				t.update(dfn[a[j]], 1);
			}
			ans = 0;
			dfs(1);
			cout << ans + (r[i] - l[i] + 1) << "\n";
			for (int j = l[i]; j <= r[i]; ++j) {
				flg[a[j]] = 0;
				t.update(dfn[a[j]], -1);
			}
		}
	}

}

namespace BF5033 {
	struct SGT {
		int res[2][50005*8];
		#define ls(p) (p << 1)
		#define rs(p) (p << 1 | 1)
		void push_up(int i) {
			res[0][i] = max(res[0][ls(i)], res[0][rs(i)]);
			res[1][i] = min(res[1][ls(i)], res[1][rs(i)]);
		}
		void build(int i, int l, int r) {
			if (l == r) {
				res[0][i] = res[1][i] = a[l];
				return;
			}
			int mid = (l + r) / 2;
			build(ls(i), l, mid);
			build(rs(i), mid + 1, r);
			push_up(i);
		}
		int query1(int i, int l, int r, int ql, int qr) {
			if (l > qr || r < ql) return 0;
			if (l >= ql && r <= qr) return res[0][i];
			int mid = (l + r) / 2;
			return max(query1(ls(i), l, mid, ql, qr), query1(rs(i), mid + 1, r, ql, qr));
		}
		
		int query2(int i, int l, int r, int ql, int qr) {
			if (l > qr || r < ql) return 1 << 30;
			if (l >= ql && r <= qr) return res[1][i];
			int mid = (l + r) / 2;
			return min(query2(ls(i), l, mid, ql, qr), query2(rs(i), mid + 1, r, ql, qr));
		}
	} t;
	void main() {

	}
}

signed main() {
	freopen("escape.in", "r", stdin);
	freopen("escape.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	int flg = 1;
	for (int i = 2; i <= n; ++i) {
		cin >> fa[i];
		flg &= (fa[i] == i - 1);
		edges[fa[i]].push_back(i);
	}
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	int sum = 0;
	for (int i = 1; i <= m; ++i) {
		cin >> l[i] >> r[i];
		sum += r[i] - l[i] + 1;
	}
	if (n <= 20000 && m <= 20000) {
		CRH380D::main();
	} else if (flg) {
		CRT5A::main();
	} else if (sum <= 5000000) {
		CR400AF::main();
	} else CRH380D::main();
	return 0;
}
